﻿Public Class FloFauNouv

#Region "Declaration"
    Dim db As New Connexion
    Dim idEsp, idDescription As Integer
    Dim TextBoxNiv As String
    Dim TextBoxCodGenr As String
    Dim TextBoxCodFam As String
    Dim TextBoxCodOrd As String
    Dim TextBoxCodEsp As String
    Dim TextBoxCodSSEsp, TextBoxCodTax As String
    Public databaseName As String
    Dim pas, Action As String
    Dim Niveau As Int16
    Public OrdreInsertion As String
    Dim contextMenu1 As New ContextMenu
    Dim menuItem1 As New MenuItem("&Avant")
    Dim menuItem2 As New MenuItem("&Aprés")
    Dim menuItem3 As New MenuItem("&Annuler")
    Dim point1 As New System.Drawing.Point

    Public WithEvents WB_NAV As New WebBrowser
    Dim Entrer As String

    Dim LibelleNiv As String()
    Dim CodeNiv As String()
    Dim NomNiv As String()
    Dim IdNiv As String()
    Dim Nomtable As String()
    Dim AutresLang As String()
    Dim NbrNiv As Integer = 0
#End Region
    Public Sub New(ByVal databaseStr As String)
        InitializeComponent()
        databaseName = databaseStr
    End Sub
    Private Sub FloFauNouv_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.TextBoxDecoupageEsp.Text = "Découpage d'espèce"
        Me.TextBoxDecoupageEsp.Enabled = False
        ' Me.ButtonAjtInvNat.Enabled = False
        Me.RadioButtonAp.Enabled = False
        Me.RadioButtonAv.Enabled = False
        Me.RadioButtonFin.Enabled = False
        Me.ButtonFerm.Enabled = False

        Me.ComboBoxListLang.Items.Add("Anglais")
        Me.ComboBoxListLang.Items.Add("Français")
        Me.ComboBoxListLang.Items.Add("Arabe")
        Me.ComboBoxListLang.Items.Add("Autre")
        Dim iter0 As Integer = 1
        While iter0 < 13
            Me.ComboBoxArrM1.Items.Add(iter0)
            Me.ComboBoxArrM2.Items.Add(iter0)
            Me.ComboBoxDepM1.Items.Add(iter0)
            Me.ComboBoxDepM2.Items.Add(iter0)
            iter0 = iter0 + 1
        End While
        iter0 = 1
        While iter0 < 5
            Me.ComboBoxArrS1.Items.Add(iter0)
            Me.ComboBoxArrS2.Items.Add(iter0)
            Me.ComboBoxDepS1.Items.Add(iter0)
            Me.ComboBoxDepS2.Items.Add(iter0)
            iter0 = iter0 + 1
        End While


        DataGridViewESP.MultiSelect = False
        DataGridViewESP.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DataGridViewESP.ReadOnly = True

        NbrNiv = 8
        LibelleNiv = New String(NbrNiv) {}
        LibelleNiv = {"Regne", "Phylum", "Classe", "Ordre", "Famille", "Genre", "Espece", "Sous Espece"}
        CodeNiv = New String(NbrNiv) {}
        NomNiv = New String(NbrNiv) {}
        IdNiv = New String(NbrNiv) {}
        AutresLang = New String(4) {}
        Nomtable = New String(19) {}

        Dim iter As Integer = 0
        db.myReq = "SELECT syscolumns.name AS colonne FROM sysobjects , syscolumns WHERE  ( sysobjects.id = syscolumns.id) And  (sysobjects.xtype = 'U') and sysobjects.name= 'FloFauSyst'"
        db.Connecter(databaseName)
        iter = 0
        While db.rdr.Read()
            Nomtable(iter) = db.rdr(0)
            iter = iter + 1
        End While
        db.Disconnecter()

        Niveau = 1
        pas = "010"
        Entrer = ""
        SelcRar()
        SelcEnd()
        SelTyp()

        miseAjour()
    End Sub


    Private Sub miseAjour()
        Entrer = ""
        Dim requeteX As String
        Dim niv As Integer = 1


        requeteX = "Select * from  [dbo].[FloFauSyst] WHERE " & Nomtable(5 + NbrNiv) & " = '" & Niveau & "' "

        While niv < Niveau
            requeteX = requeteX & "and " & Nomtable(4 + niv) & " = '" & CodeNiv(niv - 1) & "' "
            niv = niv + 1
        End While

        If Niveau = 1 Then
            Me.ButtonBack.Enabled = False
            Me.ButtonNext.Enabled = True
        ElseIf Niveau = NbrNiv Then
            Me.ButtonBack.Enabled = True
            Me.ButtonNext.Enabled = False
        Else
            Me.ButtonBack.Enabled = True
            Me.ButtonNext.Enabled = True
        End If

        db.myReq = requeteX
        db.Connecter(databaseName)
        DataGridViewESP.Rows.Clear()
        While db.rdr.Read()
            Dim iterCode As Integer = 0
            Dim result As String = ""
            DataGridViewESP.Rows.Add(db.rdr(0), db.rdr(1), db.rdr(2), db.rdr(3), db.rdr(4), db.rdr(5), db.rdr(6), db.rdr(7), db.rdr(8), db.rdr(9), db.rdr(10), db.rdr(11), db.rdr(12), db.rdr(13), db.rdr(14), db.rdr(15), db.rdr(16), db.rdr(17), db.rdr(18))
        End While
        db.Disconnecter()

        If DataGridViewESP.RowCount - 1 = 0 Or Niveau = NbrNiv Then
            Me.TextBoxCodeEsp.Text = ""
            Me.TextBoxNomEsp.Text = ""
            Me.TextBoxComt.Text = ""
            Me.TextBoxDesc1.Text = ""
            Me.TextBoxDesc2.Text = ""
            Me.TextBoxDesc3.Text = ""
            Me.TextBoxAnnEsp.Text = ""
            Me.TextBoxAutLang.Text = ""

            Me.RadioButtonAp.Enabled = False
            Me.RadioButtonAv.Enabled = False
            Me.RadioButtonFin.Enabled = False
            Me.ButtonNext.Enabled = False
            Me.ButtonAjoutHab.Enabled = False
        Else
            Me.TextBoxCodeEsp.Text = DataGridViewESP.SelectedCells(4).Value
            Me.TextBoxNomEsp.Text = DataGridViewESP.SelectedCells(14).Value
            Me.TextBoxComt.Text = ""
            Me.TextBoxDesc1.Text = ""
            Me.TextBoxDesc2.Text = ""
            Me.TextBoxDesc3.Text = ""
            Me.TextBoxAnnEsp.Text = DataGridViewESP.SelectedCells(17).Value
            Me.TextBoxAutLang.Text = ""
            Me.ButtonNext.Enabled = True
            Me.ButtonAjoutHab.Enabled = True
        End If
        If Not DataGridViewESP.RowCount - 1 = 0 Then
            Me.ButtonAjoutHab.Enabled = True
        End If

    End Sub


    Private Sub DataGridViewESP_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridViewESP.CurrentCellChanged
        If Entrer = "debut" Then
            selection()
        End If
    End Sub
    Private Sub DataGridViewESP_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridViewESP.MouseClick
        If e.Button = MouseButtons.Left And DataGridViewESP.CurrentRow.Index < DataGridViewESP.RowCount - 1 Then
            Entrer = "debut"
            selection()
        End If
    End Sub


    Private Sub selection()
        Entrer = ""
        Dim niv As Integer = 0
        Me.TextBoxDecoupageEsp.Text = ""
        If Not DataGridViewESP.SelectedCells(2).Value.ToString = "" Then

            NomNiv(Niveau - 1) = DataGridViewESP.SelectedCells(14).Value

            While niv < NbrNiv
                Me.TextBoxDecoupageEsp.Text = Me.TextBoxDecoupageEsp.Text & NomNiv(niv)
                niv = niv + 1
            End While
            Me.TextBoxCodeEsp.Text = DataGridViewESP.SelectedCells(4).Value
            Me.TextBoxNomEsp.Text = DataGridViewESP.SelectedCells(14).Value
            'SelcLang()
            'SelcRar()
            'SelcEnd()
            'SelcDesc()
            'SelTyp()


            Me.TextBoxComt.Text = ""
            Me.TextBoxDesc1.Text = ""
            Me.TextBoxDesc2.Text = ""
            Me.TextBoxDesc3.Text = ""
            Me.TextBoxAnn.Text = DataGridViewESP.SelectedCells(17).Value
            Me.TextBoxAutLang.Text = ""
            Me.oidValue.Text = Me.DataGridViewESP.SelectedCells(18).Value
            Dim listOid As List(Of String) = New List(Of String)
            listOid.Add(Me.oidValue.Text)
            _workspace.highlightNodes(_layerName, listOid)
            IdNiv(Niveau - 1) = DataGridViewESP.SelectedCells(0).RowIndex

        End If
    End Sub

    Private Sub SelcLang()
        db.myReq = "Select * from [SILM-1].[dbo].[FloFauLang] WHERE Id_FloFauSyst='" & DataGridViewESP.SelectedCells(0).Value & "'"
        db.Connecter(databaseName)
        While db.rdr.Read()
            AutresLang(0) = db.rdr(3)
            AutresLang(1) = db.rdr(4)
            AutresLang(2) = db.rdr(5)
            AutresLang(4) = db.rdr(6)
        End While
        db.Disconnecter()
    End Sub

    Private Sub SelcRar()
        Try
            Entrer = ""
            db.myReq = "Select * FROM  [dbo].[RARORGTYPOL]"
            db.Connecter(databaseName)
            Me.ComboBoxCodeCatgRar.Items.Clear()
            Me.ComboBoxNomCatgRar.Items.Clear()
            Me.ComboBoxCodeCatgRar.Items.Add("")
            Me.ComboBoxNomCatgRar.Items.Add("Tous")

            While db.rdr.Read()
                Me.ComboBoxCodeCatgRar.Items.Add(db.rdr(0))
                Me.ComboBoxNomCatgRar.Items.Add(db.rdr(2))
            End While
            Me.ComboBoxCodeCatgRar.SelectedIndex = 0
            Me.ComboBoxNomCatgRar.SelectedIndex = 0
            db.Disconnecter()
            majTyp()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub
    Private Sub ComboBoxNomCatgRar_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomCatgRar.TextChanged

        If Me.ComboBoxNomCatgRar.FindString(Me.ComboBoxNomCatgRar.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomCatgRar.Text.Length
            Me.ComboBoxNomCatgRar.SelectedIndex = Me.ComboBoxNomCatgRar.FindString(Me.ComboBoxNomCatgRar.Text)
            Me.ComboBoxNomCatgRar.SelectionStart = Pos
            Me.ComboBoxNomCatgRar.SelectionLength = Me.ComboBoxNomCatgRar.Text.Length - Pos
            Me.ComboBoxCodeCatgRar.SelectedIndex = Me.ComboBoxNomCatgRar.FindString(Me.ComboBoxNomCatgRar.Text)
            Niveau = 1
            majTyp()
        Else
            Me.ComboBoxCodeCatgRar.Text = ""
        End If
    End Sub

    Private Sub majTyp()
        Try
            Entrer = ""
            If Not Me.ComboBoxCodeCatgRar.Text = "" Then
                db.myReq = "Select * FROM  [dbo].[RARORGTYPOL] where [Id_RarOrgTypol]='" & Me.ComboBoxCodeCatgRar.Text & "'"
            Else
                db.myReq = "Select * FROM  [dbo].[RARORGTYPOL] "
            End If

            db.Connecter(databaseName)
            Me.ComboBoxCodeTypRar.Items.Clear()
            Me.ComboBoxNomTypRar.Items.Clear()
            Me.ComboBoxCodeTypRar.Items.Add("")
            Me.ComboBoxNomTypRar.Items.Add("Tous")

            While db.rdr.Read()
                If Not IsDBNull(db.rdr(0)) Then
                    Me.ComboBoxCodeTypRar.Items.Add(db.rdr(0))
                End If
                If Not IsDBNull(db.rdr(2)) Then
                    Me.ComboBoxNomTypRar.Items.Add(db.rdr(2))
                End If

            End While
            Me.ComboBoxCodeTypRar.SelectedIndex = 0
            Me.ComboBoxNomTypRar.SelectedIndex = 0
            db.Disconnecter()

        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub
    Private Sub ComboBoxNomTypRarTextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomTypRar.TextChanged

        If Me.ComboBoxNomTypRar.FindString(Me.ComboBoxNomTypRar.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomTypRar.Text.Length
            Me.ComboBoxNomTypRar.SelectedIndex = Me.ComboBoxNomTypRar.FindString(Me.ComboBoxNomTypRar.Text)
            Me.ComboBoxNomTypRar.SelectionStart = Pos
            Me.ComboBoxNomTypRar.SelectionLength = Me.ComboBoxNomTypRar.Text.Length - Pos
            Me.ComboBoxCodeTypRar.SelectedIndex = Me.ComboBoxNomTypRar.FindString(Me.ComboBoxNomTypRar.Text)
        Else
            Me.ComboBoxCodeTypRar.Text = ""
        End If
    End Sub

    Private Sub SelcEnd()
        Try
            Entrer = ""
            db.myReq = "Select * FROM  [dbo].[EndStatTyp]"
            db.Connecter(databaseName)
            Me.ComboBoxCodeCatgEnd.Items.Clear()
            Me.ComboBoxNomCatgEnd.Items.Clear()
            Me.ComboBoxCodeCatgEnd.Items.Add("")
            Me.ComboBoxNomCatgEnd.Items.Add("Tous")

            While db.rdr.Read()
                Me.ComboBoxCodeCatgEnd.Items.Add(db.rdr(0))
                Me.ComboBoxNomCatgEnd.Items.Add(db.rdr(2))
            End While
            Me.ComboBoxCodeCatgEnd.SelectedIndex = 0
            Me.ComboBoxNomCatgEnd.SelectedIndex = 0
            db.Disconnecter()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub

    Private Sub ComboBoxNomCatgEnd_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomCatgEnd.TextChanged

        If Me.ComboBoxNomCatgEnd.FindString(Me.ComboBoxNomCatgEnd.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomCatgEnd.Text.Length
            Me.ComboBoxNomCatgEnd.SelectedIndex = Me.ComboBoxNomCatgEnd.FindString(Me.ComboBoxNomCatgEnd.Text)
            Me.ComboBoxNomCatgEnd.SelectionStart = Pos
            Me.ComboBoxNomCatgEnd.SelectionLength = Me.ComboBoxNomCatgEnd.Text.Length - Pos
            Me.ComboBoxCodeCatgEnd.SelectedIndex = Me.ComboBoxNomCatgEnd.FindString(Me.ComboBoxNomCatgEnd.Text)

        Else
            Me.ComboBoxCodeCatgEnd.Text = ""
        End If
    End Sub

    Private Sub SelcDesc()
        Try
            Entrer = ""
            db.myReq = "Select * FROM  [dbo].[FloFauDsc] where [Id_Dsc]='" & Me.DataGridViewESP.SelectedCells(4).Value & "'"
            db.Connecter(databaseName)

            While db.rdr.Read()
                Me.TextBoxDesc1.Text = db.rdr(1)
                Me.TextBoxDesc2.Text = db.rdr(2)
                Me.TextBoxDesc3.Text = db.rdr(3)
            End While
            db.Disconnecter()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub


    Private Sub ButtonValLang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonValLang.Click
        If Me.ComboBoxListLang.Text = "Français" Then
            AutresLang(0) = Me.TextBoxAutLang.Text
        ElseIf Me.ComboBoxListLang.Text = "Anglais" Then
            AutresLang(1) = Me.TextBoxAutLang.Text
        ElseIf Me.ComboBoxListLang.Text = "Arabe" Then
            AutresLang(2) = Me.TextBoxAutLang.Text
        Else
            AutresLang(3) = Me.TextBoxAutLang.Text
        End If
    End Sub


    Private Sub SelTyp()
        Try
            Entrer = ""
            db.myReq = "Select * FROM  [dbo].[SttPhenTyp]"
            db.Connecter(databaseName)
            Me.ComboBoxCodeTyp.Items.Clear()
            Me.ComboBoxNomTyp.Items.Clear()
            Me.ComboBoxCodeTyp.Items.Add("")
            Me.ComboBoxNomTyp.Items.Add("Tous")

            While db.rdr.Read()
                Me.ComboBoxCodeTyp.Items.Add(db.rdr(0))
                Me.ComboBoxNomTyp.Items.Add(db.rdr(2))
            End While
            Me.ComboBoxCodeTyp.SelectedIndex = 0
            Me.ComboBoxNomTyp.SelectedIndex = 0
            db.Disconnecter()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub
    Private Sub ComboBoxNomTyp_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomTyp.TextChanged

        If Me.ComboBoxNomTyp.FindString(Me.ComboBoxNomTyp.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomTyp.Text.Length
            Me.ComboBoxNomTyp.SelectedIndex = Me.ComboBoxNomTyp.FindString(Me.ComboBoxNomTyp.Text)
            Me.ComboBoxNomTyp.SelectionStart = Pos
            Me.ComboBoxNomTyp.SelectionLength = Me.ComboBoxNomTyp.Text.Length - Pos
            Me.ComboBoxCodeTyp.SelectedIndex = Me.ComboBoxNomTyp.FindString(Me.ComboBoxNomTyp.Text)
        Else
            Me.ComboBoxCodeTyp.Text = ""
        End If
    End Sub


    Private Sub ButtonOuv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOuv.Click
        Me.ButtonFerm.Enabled = True
    End Sub

    Private Sub ButtonAjoutEsp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAjoutHab.Click
        Action = "Ajouter"
        Me.RadioButtonAp.Enabled = True
        Me.RadioButtonAv.Enabled = True
        Me.RadioButtonFin.Enabled = True
        Me.oidValue.Text = ""
        Me.TextBoxAnnEsp.Text = ""
        Me.TextBoxCodeEsp.Text = ""
        Me.TextBoxNomEsp.Text = ""
        Me.TextBoxComt.Text = ""
        Me.TextBoxDesc1.Text = ""
        Me.TextBoxDesc2.Text = ""
        Me.TextBoxDesc3.Text = ""
        Me.TextBoxAnn.Text = ""
        Me.TextBoxAutLang.Text = ""
        Me.ButtonFerm.Enabled = False
    End Sub

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        Try
            Dim Str As String
            Dim var1, var2, var3, index, MaxcodeR As Int16
            Dim Code, code2, CodeGlobal, requete As String
            CodeGlobal = ""
            Code = 0
            code2 = ""
            MaxcodeR = 0


            enregistrerDesc()
            db.myReq = "Select MAX([Id_Dsc]) from  [dbo].[FloFauDsc]"
            db.Connecter(databaseName)
            While db.rdr.Read
                idDescription = db.rdr(0)
            End While
            db.Disconnecter()

            'Récupérer le code du niveau et indexe de la ligne sélectionnée
            If Me.DataGridViewESP.RowCount - 1 > 0 Then
                db.myReq = "Select " & Nomtable(4 + Niveau) & " from  [dbo].[FloFauSyst] WHERE " & Nomtable(0) & " = '" & Me.DataGridViewESP.SelectedCells(0).Value & "'"
                db.Connecter(databaseName)
                While db.rdr.Read
                    Code = db.rdr(0)
                End While
                db.Disconnecter()
                index = DataGridViewESP.SelectedCells(0).RowIndex
            End If


            'Insérer après la ligne sélectionnée
            If RadioButtonAp.Checked Then
                If (DataGridViewESP.RowCount - 2) = index Then
                    var1 = Code
                    var2 = pas
                    var3 = (var1 + var2)
                Else
                    db.myReq = "Select " & Nomtable(4 + Niveau) & " from  [dbo].[FloFauSyst] WHERE " & Nomtable(0) & " = '" & DataGridViewESP.Rows(index + 1).Cells(0).Value & "'"
                    db.Connecter(databaseName)
                    While db.rdr.Read
                        code2 = db.rdr(0)
                    End While
                    db.Disconnecter()

                    var1 = Code
                    var2 = code2
                    var3 = (var1 + var2) / 2
                End If
            End If

            'Insérer avant la ligne sélectionnée
            If RadioButtonAv.Checked Then
                If index = 0 Then
                    code2 = 0
                Else
                    db.myReq = "Select " & Nomtable(4 + Niveau) & " from  [dbo].[FloFauSyst] WHERE " & Nomtable(0) & " = '" & DataGridViewESP.Rows(index - 1).Cells(0).Value & "'"
                    db.Connecter(databaseName)
                    While db.rdr.Read
                        code2 = db.rdr(0)
                    End While
                    db.Disconnecter()
                End If
                var1 = Code
                var2 = code2
                var3 = (var1 + var2) / 2
            End If

            'Insérer à la fin
            If RadioButtonFin.Checked Then
                Dim CodeAct As Integer
                db.myReq = "Select MAX(" & Nomtable(5 + Niveau) & " ) from  [dbo].[FloFauSyst]"
                db.Connecter(databaseName)
                If Not IsDBNull(db.rdr) And db.rdr.Read() Then
                    CodeAct = db.rdr(0)
                    var3 = pas + CodeAct
                Else
                    var3 = pas
                End If
                db.Disconnecter()
            End If

            'Le cas de la première insertion
            If Not Me.ButtonAjoutHab.Enabled Then
                var3 = pas
            End If

            If var3 < 1 Or var3 > 990 Then
                majDB()
            End If

            'Convertir la valeur du code (Système /SS Sys/Classe / SS classe / Variante) en String sous la forme xxx
            var3 = Int(var3)
            If var3.ToString.Length = 2 Then
                Str = "0" & var3.ToString
            ElseIf var3.ToString.Length = 1 Then
                Str = "00" & var3.ToString
            Else
                Str = var3.ToString
            End If

            Dim iterCode As Integer = 0
            'Inserer les valeurs des codes
            CodeNiv(Niveau - 1) = Str
            iterCode = Niveau
            While iterCode < NbrNiv
                CodeNiv(iterCode) = "000"
                iterCode = iterCode + 1
            End While



            Dim result As String
            iterCode = 0
            result = Nomtable(1) & "," & Nomtable(2) & "," & Nomtable(3) & "," & Nomtable(4)

            While iterCode < NbrNiv
                CodeGlobal = CodeGlobal & CodeNiv(iterCode)
                result = result & "," & Nomtable(5 + iterCode)
                iterCode = iterCode + 1
            End While
            result = result & "," & Nomtable(NbrNiv + 5) & "," & Nomtable(NbrNiv + 6) & "," & Nomtable(NbrNiv + 7) & "," & Nomtable(NbrNiv + 8) & "," & Nomtable(NbrNiv + 9) & "," & Nomtable(NbrNiv + 10)

            requete = " INSERT INTO  [dbo].[FloFauSyst](" & result & ") VALUES('" & Me.ComboBoxCodeCatgRar.Text & "' ,'" & Me.ComboBoxCodeTypRar.Text & "' ,'" & idDescription & "','" & Me.TextBoxCodeEsp.Text & "'"

            iterCode = 0
            While iterCode < NbrNiv
                requete = requete & " ,'" & CodeNiv(iterCode) & "'"
                iterCode = iterCode + 1
            End While
            If Me.ButtonFerm.Enabled Then
                requete = requete & ",'" & Niveau & "','" & Me.TextBoxNomEsp.Text & "','','','')"
            Else
                requete = requete & ",'" & Niveau & "','" & Me.TextBoxNomEsp.Text & "','" & Me.TextBoxAuteur.Text & "','','" & Me.TextBoxAnnEsp.Text & "','" & Me.oidValue.Text & "')"
            End If

            db.myReq = requete
            db.Connecter(databaseName)
            db.Disconnecter()

            db.myReq = "Select MAX([Id_FloFauSyst]) from  [dbo].[FLOFAUSYST]"
            db.Connecter(databaseName)
            While db.rdr.Read
                idEsp = db.rdr(0)
            End While
            db.Disconnecter()

            enregistrerAutreLang()
            'enregistrerTyp()
            miseAjour()
        Catch ex As Exception
            ' MsgBox(ex.Message)
        End Try


    End Sub

    Private Sub majDB()
        Throw New NotImplementedException
    End Sub

    Private Sub enregistrerDesc()
        db.myReq = "INSERT INTO  [dbo].[FloFauDsc] ([CarMorph_Dsc],[CarReprod_Dsc],[Repart_Dsc]) VALUES('" & Me.TextBoxDesc1.Text & "','" & Me.TextBoxDesc2.Text & "','" & Me.TextBoxDesc3.Text & "')"
        db.Connecter(databaseName)
        db.Disconnecter()
        db.myReq = "Select MAX([Id_Dsc]) from  [dbo].[FloFauDsc]"
        db.Connecter(databaseName)
        While db.rdr.Read
            idEsp = db.rdr(0)
        End While
        db.Disconnecter()
    End Sub

    Private Sub enregistrerAutreLang()
        Try
            db.myReq = "INSERT INTO  [dbo].[FLOFAULANG] ([Id_FloFauSyst],[CODE_LAN],[NOMENG_LAN],[NOMFRAN_LAN],[NOMARB_LAN],[NOMDIAL_LAN]) VALUES( '" & idEsp & "','','" & AutresLang(0) & "','" & AutresLang(1) & "','" & AutresLang(2) & "','" & AutresLang(3) & "')"
            db.Connecter(databaseName)
            db.Disconnecter()
        Catch ex As Exception

        End Try
        
    End Sub

    Private Sub enregistrerTyp()
        Try
            db.myReq = "INSERT INTO  [dbo].[FlauPhenMa_FloFauSys] ([Id_SttPhenTyp],[Id_FloFauSyst],[DebMoi_MgrSys],[DebSem_MgrSys],[FinMoi_MgrSys],[FinSem_MgrSys],[Expl_MgrSys]) VALUES('" & Me.ComboBoxCodeTyp.Text & "','" & idEsp & "','" & Me.ComboBoxDepM1.Text & "','" & Me.ComboBoxDepS1.Text & "','" & Me.ComboBoxArrM1.Text & "','" & Me.ComboBoxArrS1.Text & "','" & Me.TextBoxComt.Text & "')"
            db.Connecter(databaseName)
            db.Disconnecter()
        Catch ex As Exception

        End Try
       

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim typX As New RarOrgTypol(databaseName)
        typX.Text = "Typologie"
        typX.Table = "RarOrgTypol"
        typX.ShowDialog(Me)
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Dim typ1 As New TypologieNiv1CategForm(databaseName)
        typ1.Text = "Catégorie"
        typ1.table1 = "RarOrgTypol"
        typ1.table2 = "RarStatTyp"
        typ1.ShowDialog(Me)
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Dim typ1 As New TypologieNiv1Form(databaseName)
        typ1.Text = "Catégorie"
        typ1.Table = "EndStatTyp"
        typ1.ShowDialog(Me)
    End Sub

    Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
        Dim typ1 As New TypologieNiv1Form(databaseName)
        typ1.Text = "Catégorie"
        typ1.Table = "SttPhenTyp"
        typ1.Visible = True
    End Sub

    Private Sub ButtonNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNext.Click
        Entrer = ""

        Niveau = Niveau + 1
        Me.Label7.Text = LibelleNiv(Niveau)

        db.myReq = "Select * from  [dbo].[FLOFAUSYST] WHERE " & Nomtable(0) & " = '" & DataGridViewESP.SelectedCells(0).Value & "'"
        db.Connecter(databaseName)
        While db.rdr.Read
            CodeNiv(Niveau - 2) = db.rdr(2 + Niveau)
        End While

        miseAjour()
    End Sub

    Private Sub ButtonBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBack.Click
        Dim niv As Integer = 0
        Me.TextBoxDecoupageEsp.Text = ""
        Entrer = ""
        Niveau = Niveau - 1
        Me.Label7.Text = LibelleNiv(Niveau - 1)
        While niv < Niveau
            Me.TextBoxDecoupageEsp.Text = Me.TextBoxDecoupageEsp.Text & NomNiv(niv)
            niv = niv + 1
        End While
        miseAjour()
        DataGridViewESP.Rows(IdNiv(Niveau - 1)).Selected = True
    End Sub

    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        Me.Close()
    End Sub




    ''' <summary>
    ''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Private _workspace As Object
    Private _layerName As String
    Private geoForm As GeoLocation = Nothing
    Property layerName() As String
        Get
            Return _layerName
        End Get
        Set(ByVal value As String)
            _layerName = value
        End Set
    End Property

    Property workspace() As Object
        Get
            Return _workspace
        End Get
        Set(ByVal value As Object)
            _workspace = value
        End Set
    End Property

    Private Sub btnGetGeo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetGeo.Click
        If geoForm IsNot Nothing AndAlso geoForm.Visible Then
            Return
        End If
        workspace.showGeolocation(oidValue)
        'geoForm = New GeoLocation()
        'geoForm.Show()
        'geoForm.workspace = Me.workspace
        'geoForm.oidParentText = oidValue

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            db.myReq = " DELETE FROM  [dbo].[FLOFAUSYST]  WHERE [Id_FloFauSyst]='" & DataGridViewESP.SelectedCells(0).Value & "'"
            db.Connecter(databaseName)
            db.Disconnecter()
            miseAjour()
            If DataGridViewESP.RowCount - 1 = 0 Then
                Return
            End If
            Dim listOid As List(Of String) = New List(Of String)

            listOid.Add(DataGridViewESP.SelectedCells(18).Value)

            _workspace.deleteNodes(_layerName, listOid)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub ButtonModifier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonModifier.Click
        db.myReq = "Update  [dbo].[FLOFAUSYST] SET [CodTax_FloFauSyst]= '" & Me.TextBoxCodeEsp.Text & "',[NomSci_FloFauSyst]= '" & Me.TextBoxNomEsp.Text & "',[AutTax_FloFauSyst]='" & Me.TextBoxAuteur.Text & "',[SIGID]='" & Me.oidValue.Text & "'  WHERE [Id_FloFauSyst]='" & DataGridViewESP.SelectedCells(0).Value & "'"

        db.Connecter(databaseName)
        db.Disconnecter()

    End Sub

    Private Sub DataGridViewESP_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewESP.CellClick

    End Sub

    Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.Click

    End Sub


End Class